package com.smarthome.emqx_to_mysql;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/usr")
public class UserController {
    @Resource
    private UserService userService;
    @PostMapping("/webhook")
    public void ResponseMes(@RequestBody Data data){
        System.out.println(data);
        User user=new User();
        String[] res=data.payload.split(",");
        for (int i=0;i< res.length; i++){
            user.setDevice(data.clientid);
            user.setTemp(Float.parseFloat(res[0]));
            user.setHumi(Float.parseFloat(res[1]));
            user.setTemp1(Float.parseFloat(res[2]));
            user.setPres(Integer.parseInt(res[3]));
        }
        userService.addUser(user);
        System.out.println(user);
    }
}
